rm(list=ls())
install.packages("foreign")
install.packages("ggplot2")
install.packages("dplyr")
install.packages("xlsx")

library(foreign)
library(ggplot2)
library(dplyr)
library(xlsx)

# set working directory

# Figure A1: Unweighted vs. weighted
variables <- c("0b.FeatDamage", "1.FeatDamage", "2.FeatDamage", "3.FeatDamage",
               "0b.FeatDead", "1.FeatDead",
               "0b.FeatHHInc", "1.FeatHHInc", "2.FeatHHInc", "3.FeatHHInc",
               "0b.FeatUnemp", "1.FeatUnemp", "2.FeatUnemp", "3.FeatUnemp",
               "1b.FeatPresVote", "2.FeatPresVote", "3.FeatPresVote", "4.FeatPresVote", "5.FeatPresVote")


model.rep <- c("main_weighted.txt")
rep <- read.table(model.rep,header=TRUE)
new_row <- c(0,0)
rep <- rbind(rep, new_row)
rep$ord <- 1:nrow(rep)
rep$ord[rep$ord==20] <- 6.5
rep <- rep[order(rep$ord),]
rep <- within(rep, rm(ord))

model.dem <- c("main_unweighted.txt")
dem <- read.table(model.dem,header=TRUE)
new_row <- c(0,0)
dem <- rbind(dem, new_row)
dem$ord <- 1:nrow(dem)
dem$ord[dem$ord==20] <- 6.5
dem <- dem[order(dem$ord),]
dem <- within(dem, rm(ord))


# Drop the constants
rep <- rep[-c(nrow(rep)), ]
dem <- dem[-c(nrow(dem)), ]


# calculate standard errors
rep$r1 <- sqrt(rep$r1)
dem$r1 <- sqrt(dem$r1)

# calculate confidence intervals
rep$lower <- rep$y1  - 1.96*rep$r1
rep$upper <- rep$y1  + 1.96*rep$r1

dem$lower <- dem$y1  - 1.96*dem$r1
dem$upper <- dem$y1  + 1.96*dem$r1

colnames(rep) <- c("pe", "se", "lower", "upper")
colnames(dem) <- c("pe", "se", "lower", "upper")

# add order variable 
rep$order <- c(seq(.8,3.8,1), seq(5.8,6.8,1), seq(8.8,11.8,1), seq(13.8,16.8,1), seq(18.8,22.8,1))
dem$order <- rep$order + .4

# add variable to frames
rep$variables <- variables
dem$variables <- variables

# add model variable
rep$model <- "Weighted"
dem$model <- "Unweighted"

mydata <- rbind(rep,dem)
mydata$order <- mydata$order * -1 + 24

xlabelsN <- c("70% Democrat, 30% Republican", "60% Democrat, 40% Republican", "30% Democrat, 70% Republican", "40% Democrat, 60% Republican", "50% Democrat, 50% Republican", "Presidential Vote in 2012:           ", "9%", "7%", "5%", "3%", "Unemployment Rate:                  ", "$10,000", "$40,000", "$70,000", "$100,000", "Average Household Income:       ", "5", "0", "Number of Fatalities:                   ", "$24 million", "$4 million", "$1 million", "$100,000", "Economic Damage:                    ")

#mydata <- mutate(mydata, pe = pe*100, lower = lower*100, upper = upper*100)
mydata$model <- as.factor(mydata$model)
mydata$model <- factor(mydata$model, levels = c(levels(mydata$model)[2],levels(mydata$model)[1]))

p <- ggplot(mydata, aes(x=order, y=pe, colour=model)) + 
  geom_point(aes(x = order, y = pe, colour = model), show.legend = T, size = 2) +
  geom_segment(aes(x = order, xend = order, y = lower, yend = upper), show.legend = T) 
p <- p + coord_flip(ylim = c(-0.7, 1.5), xlim = c(1, 24)) + theme_bw()
p <- p + scale_x_continuous(name="", breaks=seq(1,24,1),labels=xlabelsN)
p <- p + scale_y_continuous(name="Change in Relief Aid (million $)")
p <- p + geom_hline(yintercept = 0,size=.5,colour="black",linetype="dashed") 
figA1 <- p + theme(legend.position = c(.83, 0.965),
               legend.background = element_rect(fill="transparent"),
               legend.key = element_blank(), axis.text = element_text(size = 12)) + scale_colour_grey(name = "") 

figA1
ggsave("FigureA1_weighted_unweighted.pdf", width=9, height=8)


###########################################################
# Figure A2: Likely voters vs. Adult Population (weighted)
variables <- c("0b.FeatDamage", "1.FeatDamage", "2.FeatDamage", "3.FeatDamage",
               "0b.FeatDead", "1.FeatDead",
               "0b.FeatHHInc", "1.FeatHHInc", "2.FeatHHInc", "3.FeatHHInc",
               "0b.FeatUnemp", "1.FeatUnemp", "2.FeatUnemp", "3.FeatUnemp",
               "1b.FeatPresVote", "2.FeatPresVote", "3.FeatPresVote", "4.FeatPresVote", "5.FeatPresVote")


model.rep <- c("olscon_main.txt")
rep <- read.table(model.rep,header=TRUE)
new_row <- c(0,0)
rep <- rbind(rep, new_row)
rep$ord <- 1:nrow(rep)
rep$ord[rep$ord==20] <- 6.5
rep <- rep[order(rep$ord),]
rep <- within(rep, rm(ord))

model.dem <- c("olscon_main_votingpop.txt")
dem <- read.table(model.dem,header=TRUE)
new_row <- c(0,0)
dem <- rbind(dem, new_row)
dem$ord <- 1:nrow(dem)
dem$ord[dem$ord==20] <- 6.5
dem <- dem[order(dem$ord),]
dem <- within(dem, rm(ord))


# Drop the constants
rep <- rep[-c(nrow(rep)), ]
dem <- dem[-c(nrow(dem)), ]


# calculate standard errors
rep$r1 <- sqrt(rep$r1)
dem$r1 <- sqrt(dem$r1)

# calculate confidence intervals
rep$lower <- rep$y1  - 1.96*rep$r1
rep$upper <- rep$y1  + 1.96*rep$r1

dem$lower <- dem$y1  - 1.96*dem$r1
dem$upper <- dem$y1  + 1.96*dem$r1

colnames(rep) <- c("pe", "se", "lower", "upper")
colnames(dem) <- c("pe", "se", "lower", "upper")

# add order variable 
rep$order <- c(seq(.8,3.8,1), seq(5.8,6.8,1), seq(8.8,11.8,1), seq(13.8,16.8,1), seq(18.8,22.8,1))
dem$order <- rep$order + .4

# add variable to frames
rep$variables <- variables
dem$variables <- variables

# add model variable
rep$model <- "Full sample"
dem$model <- "Likely voters"

mydata <- rbind(rep,dem)
mydata$order <- mydata$order * -1 + 24

xlabelsN <- c("70% Democrat, 30% Republican", "60% Democrat, 40% Republican", "30% Democrat, 70% Republican", "40% Democrat, 60% Republican", "50% Democrat, 50% Republican", "Presidential Vote in 2012:           ", "9%", "7%", "5%", "3%", "Unemployment Rate:                  ", "$10,000", "$40,000", "$70,000", "$100,000", "Average Household Income:       ", "5", "0", "Number of Fatalities:                   ", "$24 million", "$4 million", "$1 million", "$100,000", "Economic Damage:                    ")

mydata$model <- as.factor(mydata$model)
mydata$model <- factor(mydata$model, levels = c(levels(mydata$model)[1],levels(mydata$model)[2]))

p <- ggplot(mydata, aes(x=order, y=pe, colour=model)) + 
  geom_point(aes(x = order, y = pe, colour = model), show.legend = T, size = 2) +
  geom_segment(aes(x = order, xend = order, y = lower, yend = upper), show.legend = T) 
p <- p + coord_flip(ylim = c(-0.7, 1.5), xlim = c(1, 24)) + theme_bw()
p <- p + scale_x_continuous(name="", breaks=seq(1,24,1),labels=xlabelsN)
p <- p + scale_y_continuous(name="Change in Relief Aid (million $)")
p <- p + geom_hline(yintercept = 0,size=.5,colour="black",linetype="dashed") 
fig2 <- p + theme(legend.position = c(.83, 0.965),
                   legend.background = element_rect(fill="transparent"),
                   legend.key = element_blank(), axis.text = element_text(size = 12)) + scale_colour_grey(name = "") 

fig2
ggsave("FigureA2_main_VotingPopulation.pdf", width=9, height=8)

###########################################################
# Figure A3: By affectedness
variables <- c("0b.FeatDamage", "1.FeatDamage", "2.FeatDamage", "3.FeatDamage",
               "0b.FeatDead", "1.FeatDead",
               "0b.FeatHHInc", "1.FeatHHInc", "2.FeatHHInc", "3.FeatHHInc",
               "0b.FeatUnemp", "1.FeatUnemp", "2.FeatUnemp", "3.FeatUnemp",
               "1b.FeatPresVote", "2.FeatPresVote", "3.FeatPresVote", "4.FeatPresVote", "5.FeatPresVote")

model.rep <- c("olscon_aff_high.txt")
rep <- read.table(model.rep,header=TRUE)
new_row <- c(0,0)
rep <- rbind(rep, new_row)
rep$ord <- 1:nrow(rep)
rep$ord[rep$ord==20] <- 6.5
rep <- rep[order(rep$ord),]
rep <- within(rep, rm(ord))

model.dem <- c("olscon_aff_low.txt")
dem <- read.table(model.dem,header=TRUE)
new_row <- c(0,0)
dem <- rbind(dem, new_row)
dem$ord <- 1:nrow(dem)
dem$ord[dem$ord==20] <- 6.5
dem <- dem[order(dem$ord),]
dem <- within(dem, rm(ord))


# Drop the constants
rep <- rep[-c(nrow(rep)), ]
dem <- dem[-c(nrow(dem)), ]


# calculate standard errors
rep$r1 <- sqrt(rep$r1)
dem$r1 <- sqrt(dem$r1)

# calculate confidence intervals
rep$lower <- rep$y1  - 1.96*rep$r1
rep$upper <- rep$y1  + 1.96*rep$r1

dem$lower <- dem$y1  - 1.96*dem$r1
dem$upper <- dem$y1  + 1.96*dem$r1

colnames(rep) <- c("pe", "se", "lower", "upper")
colnames(dem) <- c("pe", "se", "lower", "upper")

# add order variable 
rep$order <- c(seq(.8,3.8,1), seq(5.8,6.8,1), seq(8.8,11.8,1), seq(13.8,16.8,1), seq(18.8,22.8,1))
dem$order <- rep$order + .4

# add variable to frames
rep$variables <- variables
dem$variables <- variables

# add model variable
rep$model <- "Affected"
dem$model <- "Not affected"

mydata <- rbind(rep,dem)
mydata$order <- mydata$order * -1 + 24

xlabelsN <- c("70% Democrat, 30% Republican", "60% Democrat, 40% Republican", "30% Democrat, 70% Republican", "40% Democrat, 60% Republican", "50% Democrat, 50% Republican", "Presidential Vote in 2012:           ", "9%", "7%", "5%", "3%", "Unemployment Rate:                  ", "$10,000", "$40,000", "$70,000", "$100,000", "Average Household Income:       ", "5", "0", "Number of Fatalities:                   ", "$24 million", "$4 million", "$1 million", "$100,000", "Economic Damage:                    ")

mydata$model <- as.factor(mydata$model)
mydata$model <- factor(mydata$model, levels = c(levels(mydata$model)[1],levels(mydata$model)[2]))

p <- ggplot(mydata, aes(x=order, y=pe, colour=model)) + 
  geom_point(aes(x = order, y = pe, colour = model), show.legend = T, size = 2) +
  geom_segment(aes(x = order, xend = order, y = lower, yend = upper), show.legend = T) 
p <- p + coord_flip(ylim = c(-0.7, 1.5), xlim = c(1, 24)) + theme_bw()
p <- p + scale_x_continuous(name="", breaks=seq(1,24,1),labels=xlabelsN)
p <- p + scale_y_continuous(name="Change in Relief Aid (million $)")
p <- p + geom_hline(yintercept = 0,size=.5,colour="black",linetype="dashed") 
fig3 <- p + theme(legend.position = c(.83, 0.965),
                  legend.background = element_rect(fill="transparent"),
                  legend.key = element_blank(), axis.text = element_text(size = 12)) + scale_colour_grey(name = "") 

fig3
ggsave("FigureA3_affectedness.pdf", width=9, height=8)

###########################################################
# Figure A4: By attentiveness
variables <- c("0b.FeatDamage", "1.FeatDamage", "2.FeatDamage", "3.FeatDamage",
               "0b.FeatDead", "1.FeatDead",
               "0b.FeatHHInc", "1.FeatHHInc", "2.FeatHHInc", "3.FeatHHInc",
               "0b.FeatUnemp", "1.FeatUnemp", "2.FeatUnemp", "3.FeatUnemp",
               "1b.FeatPresVote", "2.FeatPresVote", "3.FeatPresVote", "4.FeatPresVote", "5.FeatPresVote")

model.rep <- c("olscon_att_high.txt")
rep <- read.table(model.rep,header=TRUE)
new_row <- c(0,0)
rep <- rbind(rep, new_row)
rep$ord <- 1:nrow(rep)
rep$ord[rep$ord==20] <- 6.5
rep <- rep[order(rep$ord),]
rep <- within(rep, rm(ord))

model.dem <- c("olscon_att_low.txt")
dem <- read.table(model.dem,header=TRUE)
new_row <- c(0,0)
dem <- rbind(dem, new_row)
dem$ord <- 1:nrow(dem)
dem$ord[dem$ord==20] <- 6.5
dem <- dem[order(dem$ord),]
dem <- within(dem, rm(ord))


# Drop the constants
rep <- rep[-c(nrow(rep)), ]
dem <- dem[-c(nrow(dem)), ]


# calculate standard errors
rep$r1 <- sqrt(rep$r1)
dem$r1 <- sqrt(dem$r1)

# calculate confidence intervals
rep$lower <- rep$y1  - 1.96*rep$r1
rep$upper <- rep$y1  + 1.96*rep$r1

dem$lower <- dem$y1  - 1.96*dem$r1
dem$upper <- dem$y1  + 1.96*dem$r1

colnames(rep) <- c("pe", "se", "lower", "upper")
colnames(dem) <- c("pe", "se", "lower", "upper")

# add order variable 
rep$order <- c(seq(.8,3.8,1), seq(5.8,6.8,1), seq(8.8,11.8,1), seq(13.8,16.8,1), seq(18.8,22.8,1))
dem$order <- rep$order + .4

# add variable to frames
rep$variables <- variables
dem$variables <- variables

# add model variable
rep$model <- "Attention question correct: Yes"
dem$model <- "Attention question correct: No"

mydata <- rbind(rep,dem)
mydata$order <- mydata$order * -1 + 24

xlabelsN <- c("70% Democrat, 30% Republican", "60% Democrat, 40% Republican", "30% Democrat, 70% Republican", "40% Democrat, 60% Republican", "50% Democrat, 50% Republican", "Presidential Vote in 2012:           ", "9%", "7%", "5%", "3%", "Unemployment Rate:                  ", "$10,000", "$40,000", "$70,000", "$100,000", "Average Household Income:       ", "5", "0", "Number of Fatalities:                   ", "$24 million", "$4 million", "$1 million", "$100,000", "Economic Damage:                    ")

#mydata <- mutate(mydata, pe = pe*100, lower = lower*100, upper = upper*100)
mydata$model <- as.factor(mydata$model)
mydata$model <- factor(mydata$model, levels = c(levels(mydata$model)[2],levels(mydata$model)[1]))

p <- ggplot(mydata, aes(x=order, y=pe, colour=model)) + 
  geom_point(aes(x = order, y = pe, colour = model), show.legend = T, size = 2) +
  geom_segment(aes(x = order, xend = order, y = lower, yend = upper), show.legend = T) 
p <- p + coord_flip(ylim = c(-0.6, 1.6), xlim = c(1, 24)) + theme_bw()
p <- p + scale_x_continuous(name="", breaks=seq(1,24,1),labels=xlabelsN)
p <- p + scale_y_continuous(name="Change in Relief Aid (million $)")
p <- p + geom_hline(yintercept = 0,size=.5,colour="black",linetype="dashed") 
fig4 <- p + theme(legend.position = c(.83, 0.965),
                  legend.background = element_rect(fill="transparent"),
                  legend.key = element_blank(), axis.text = element_text(size = 12)) + scale_colour_grey(name = "") 

fig4
ggsave("FigureA4_attentiveness.pdf", width=9, height=8)

###########################################################
# Figure A5: By completion time
variables <- c("0b.FeatDamage", "1.FeatDamage", "2.FeatDamage", "3.FeatDamage",
               "0b.FeatDead", "1.FeatDead",
               "0b.FeatHHInc", "1.FeatHHInc", "2.FeatHHInc", "3.FeatHHInc",
               "0b.FeatUnemp", "1.FeatUnemp", "2.FeatUnemp", "3.FeatUnemp",
               "1b.FeatPresVote", "2.FeatPresVote", "3.FeatPresVote", "4.FeatPresVote", "5.FeatPresVote")

model.rep <- c("time_a.txt")
rep <- read.table(model.rep,header=TRUE)
new_row <- c(0,0)
rep <- rbind(rep, new_row)
rep$ord <- 1:nrow(rep)
rep$ord[rep$ord==20] <- 6.5
rep <- rep[order(rep$ord),]
rep <- within(rep, rm(ord))

model.dem <- c("time_d.txt")
dem <- read.table(model.dem,header=TRUE)
new_row <- c(0,0)
dem <- rbind(dem, new_row)
dem$ord <- 1:nrow(dem)
dem$ord[dem$ord==20] <- 6.5
dem <- dem[order(dem$ord),]
dem <- within(dem, rm(ord))


# Drop the constants
rep <- rep[-c(nrow(rep)), ]
dem <- dem[-c(nrow(dem)), ]


# calculate standard errors
rep$r1 <- sqrt(rep$r1)
dem$r1 <- sqrt(dem$r1)

# calculate confidence intervals
rep$lower <- rep$y1  - 1.96*rep$r1
rep$upper <- rep$y1  + 1.96*rep$r1

dem$lower <- dem$y1  - 1.96*dem$r1
dem$upper <- dem$y1  + 1.96*dem$r1

colnames(rep) <- c("pe", "se", "lower", "upper")
colnames(dem) <- c("pe", "se", "lower", "upper")

# add order variable 
rep$order <- c(seq(.8,3.8,1), seq(5.8,6.8,1), seq(8.8,11.8,1), seq(13.8,16.8,1), seq(18.8,22.8,1))
dem$order <- rep$order + .4

# add variable to frames
rep$variables <- variables
dem$variables <- variables

# add model variable
rep$model <- "Completion time: High"
dem$model <- "Completion time: Low"

mydata <- rbind(rep,dem)
mydata$order <- mydata$order * -1 + 24

xlabelsN <- c("70% Democrat, 30% Republican", "60% Democrat, 40% Republican", "30% Democrat, 70% Republican", "40% Democrat, 60% Republican", "50% Democrat, 50% Republican", "Presidential Vote in 2012:           ", "9%", "7%", "5%", "3%", "Unemployment Rate:                  ", "$10,000", "$40,000", "$70,000", "$100,000", "Average Household Income:       ", "5", "0", "Number of Fatalities:                   ", "$24 million", "$4 million", "$1 million", "$100,000", "Economic Damage:                    ")

#mydata <- mutate(mydata, pe = pe*100, lower = lower*100, upper = upper*100)
mydata$model <- as.factor(mydata$model)
mydata$model <- factor(mydata$model, levels = c(levels(mydata$model)[1],levels(mydata$model)[2]))

p <- ggplot(mydata, aes(x=order, y=pe, colour=model)) + 
  geom_point(aes(x = order, y = pe, colour = model), show.legend = T, size = 2) +
  geom_segment(aes(x = order, xend = order, y = lower, yend = upper), show.legend = T) 
p <- p + coord_flip(ylim = c(-0.7, 2), xlim = c(1, 24)) + theme_bw()
p <- p + scale_x_continuous(name="", breaks=seq(1,24,1),labels=xlabelsN)
p <- p + scale_y_continuous(name="Change in Relief Aid (million $)")
p <- p + geom_hline(yintercept = 0,size=.5,colour="black",linetype="dashed") 
fig5 <- p + theme(legend.position = c(.83, 0.965),
                  legend.background = element_rect(fill="transparent"),
                  legend.key = element_blank(), axis.text = element_text(size = 12)) + scale_colour_grey(name = "") 

fig5
ggsave("FigureA5_completiontime.pdf", width=9, height=8)

###########################################################
# Figure A6: By race
variables <- c("0b.FeatDamage", "1.FeatDamage", "2.FeatDamage", "3.FeatDamage",
               "0b.FeatDead", "1.FeatDead",
               "0b.FeatHHInc", "1.FeatHHInc", "2.FeatHHInc", "3.FeatHHInc",
               "0b.FeatUnemp", "1.FeatUnemp", "2.FeatUnemp", "3.FeatUnemp",
               "1b.FeatPresVote", "2.FeatPresVote", "3.FeatPresVote", "4.FeatPresVote", "5.FeatPresVote")

model.rep <- c("ols_white.txt")
rep <- read.table(model.rep,header=TRUE)
new_row <- c(0,0)
rep <- rbind(rep, new_row)
rep$ord <- 1:nrow(rep)
rep$ord[rep$ord==20] <- 6.5
rep <- rep[order(rep$ord),]
rep <- within(rep, rm(ord))

model.dem <- c("ols_nonwhite.txt")
dem <- read.table(model.dem,header=TRUE)
new_row <- c(0,0)
dem <- rbind(dem, new_row)
dem$ord <- 1:nrow(dem)
dem$ord[dem$ord==20] <- 6.5
dem <- dem[order(dem$ord),]
dem <- within(dem, rm(ord))


# Drop the constants
rep <- rep[-c(nrow(rep)), ]
dem <- dem[-c(nrow(dem)), ]


# calculate standard errors
rep$r1 <- sqrt(rep$r1)
dem$r1 <- sqrt(dem$r1)

# calculate confidence intervals
rep$lower <- rep$y1  - 1.96*rep$r1
rep$upper <- rep$y1  + 1.96*rep$r1

dem$lower <- dem$y1  - 1.96*dem$r1
dem$upper <- dem$y1  + 1.96*dem$r1

colnames(rep) <- c("pe", "se", "lower", "upper")
colnames(dem) <- c("pe", "se", "lower", "upper")

# add order variable 
rep$order <- c(seq(.8,3.8,1), seq(5.8,6.8,1), seq(8.8,11.8,1), seq(13.8,16.8,1), seq(18.8,22.8,1))
dem$order <- rep$order + .4

# add variable to frames
rep$variables <- variables
dem$variables <- variables

# add model variable
rep$model <- "White"
dem$model <- "Non-White"

mydata <- rbind(rep,dem)
mydata$order <- mydata$order * -1 + 24

xlabelsN <- c("70% Democrat, 30% Republican", "60% Democrat, 40% Republican", "30% Democrat, 70% Republican", "40% Democrat, 60% Republican", "50% Democrat, 50% Republican", "Presidential Vote in 2012:           ", "9%", "7%", "5%", "3%", "Unemployment Rate:                  ", "$10,000", "$40,000", "$70,000", "$100,000", "Average Household Income:       ", "5", "0", "Number of Fatalities:                   ", "$24 million", "$4 million", "$1 million", "$100,000", "Economic Damage:                    ")

#mydata <- mutate(mydata, pe = pe*100, lower = lower*100, upper = upper*100)
mydata$model <- as.factor(mydata$model)
mydata$model <- factor(mydata$model, levels = c(levels(mydata$model)[2],levels(mydata$model)[1]))

p <- ggplot(mydata, aes(x=order, y=pe, colour=model)) + 
  geom_point(aes(x = order, y = pe, colour = model), show.legend = T, size = 2) +
  geom_segment(aes(x = order, xend = order, y = lower, yend = upper), show.legend = T) 
p <- p + coord_flip(ylim = c(-0.7, 1.5), xlim = c(1, 24)) + theme_bw()
p <- p + scale_x_continuous(name="", breaks=seq(1,24,1),labels=xlabelsN)
p <- p + scale_y_continuous(name="Change in Relief Aid (million $)")
p <- p + geom_hline(yintercept = 0,size=.5,colour="black",linetype="dashed") 
fig6 <- p + theme(legend.position = c(.83, 0.965),
                  legend.background = element_rect(fill="transparent"),
                  legend.key = element_blank(), axis.text = element_text(size = 12)) + scale_colour_grey(name = "") 

fig6
ggsave("FigureA6_white_nonwhite.pdf", width=9, height=8)

###########################################################
# Figure A7: By partisan identification
variables <- c("0b.FeatDamage", "1.FeatDamage", "2.FeatDamage", "3.FeatDamage",
               "0b.FeatDead", "1.FeatDead",
               "0b.FeatHHInc", "1.FeatHHInc", "2.FeatHHInc", "3.FeatHHInc",
               "0b.FeatUnemp", "1.FeatUnemp", "2.FeatUnemp", "3.FeatUnemp",
               "1b.FeatPresVote", "2.FeatPresVote", "3.FeatPresVote", "4.FeatPresVote", "5.FeatPresVote")

model.rep <- c("ols_southern_rep.txt")
rep <- read.table(model.rep,header=TRUE)
new_row <- c(0,0)
rep <- rbind(rep, new_row)
rep$ord <- 1:nrow(rep)
rep$ord[rep$ord==20] <- 6.5
rep <- rep[order(rep$ord),]
rep <- within(rep, rm(ord))

model.dem <- c("ols_southern_dems.txt")
dem <- read.table(model.dem,header=TRUE)
new_row <- c(0,0)
dem <- rbind(dem, new_row)
dem$ord <- 1:nrow(dem)
dem$ord[dem$ord==20] <- 6.5
dem <- dem[order(dem$ord),]
dem <- within(dem, rm(ord))


# Drop the constants
rep <- rep[-c(nrow(rep)), ]
dem <- dem[-c(nrow(dem)), ]


# calculate standard errors
rep$r1 <- sqrt(rep$r1)
dem$r1 <- sqrt(dem$r1)

# calculate confidence intervals
rep$lower <- rep$y1  - 1.96*rep$r1
rep$upper <- rep$y1  + 1.96*rep$r1

dem$lower <- dem$y1  - 1.96*dem$r1
dem$upper <- dem$y1  + 1.96*dem$r1

colnames(rep) <- c("pe", "se", "lower", "upper")
colnames(dem) <- c("pe", "se", "lower", "upper")

# add order variable 
rep$order <- c(seq(.8,3.8,1), seq(5.8,6.8,1), seq(8.8,11.8,1), seq(13.8,16.8,1), seq(18.8,22.8,1))
dem$order <- rep$order + .4

# add variable to frames
rep$variables <- variables
dem$variables <- variables

# add model variable
rep$model <- "Southern Republicans"
dem$model <- "Southern Democrats"

mydata <- rbind(rep,dem)
mydata$order <- mydata$order * -1 + 24

xlabelsN <- c("70% Democrat, 30% Republican", "60% Democrat, 40% Republican", "30% Democrat, 70% Republican", "40% Democrat, 60% Republican", "50% Democrat, 50% Republican", "Presidential Vote in 2012:           ", "9%", "7%", "5%", "3%", "Unemployment Rate:                  ", "$10,000", "$40,000", "$70,000", "$100,000", "Average Household Income:       ", "5", "0", "Number of Fatalities:                   ", "$24 million", "$4 million", "$1 million", "$100,000", "Economic Damage:                    ")

#mydata <- mutate(mydata, pe = pe*100, lower = lower*100, upper = upper*100)
mydata$model <- as.factor(mydata$model)
mydata$model <- factor(mydata$model, levels = c(levels(mydata$model)[2],levels(mydata$model)[1]))

p <- ggplot(mydata, aes(x=order, y=pe, colour=model)) + 
  geom_point(aes(x = order, y = pe, colour = model), show.legend = T, size = 2) +
  geom_segment(aes(x = order, xend = order, y = lower, yend = upper), show.legend = T) 
p <- p + coord_flip(ylim = c(-0.5, 1.8), xlim = c(1, 24)) + theme_bw()
p <- p + scale_x_continuous(name="", breaks=seq(1,24,1),labels=xlabelsN)
p <- p + scale_y_continuous(name="Change in Relief Aid (million $)")
p <- p + geom_hline(yintercept = 0,size=.5,colour="black",linetype="dashed") 
fig7 <- p + theme(legend.position = c(.8, 0.965),
                  legend.background = element_rect(fill="transparent"),
                  legend.key = element_blank(), axis.text = element_text(size = 12)) + scale_colour_grey(name = "") 

fig7
ggsave("FigureA7_southernrep_dems.pdf", width=9, height=8)

###########################################################
# Figure A8: Tobit estimates
model <- c("olscon_main_tobit.txt") 
modelname <- c("Change in relief aid")

d <- read.table(model, header=TRUE)
new_row <- c(0,0)
d <- rbind(d, new_row)
d$ord <- 1:nrow(d)
d$ord[d$ord==20] <- 6.5
d <- d[order(d$ord),]
d <- within(d, rm(ord))

# Drop the constant
d <- d[-c(length(d$y1)), ]
d <- d[-c(length(d$y1)), ]

colnames(d) <- c("pe", "se")

d$se <- sqrt(d$se)

d$lower <- d$pe  - 1.96*d$se
d$upper <- d$pe  + 1.96*d$se

d$order <- 1:nrow(d)

#group vars
Damage <- c("0b.FeatDamage", "1.FeatDamage", "2.FeatDamage", "3.FeatDamage")
Fatalities <- c("0b.FeatDead", "1.FeatDead", "2.FeatDead", "3.FeatDead")
Income <- c("0b.FeatHHInc", "1.FeatHHInc", "2.FeatHHInc", "3.FeatHHInc")
Unemployment <- c("0b.FeatUnemp", "1.FeatUnemp", "2.FeatUnemp", "3.FeatUnemp")
VoteShare <- c("1b.FeatPresVote", "2.FeatPresVote", "3.FeatPresVote", "4.FeatPresVote", "5.FeatPresVote")


d$gruppe <- NA
d$var <- rownames(d)
d$var[d$var==20] <- "0b.FeatHHInc"
d$var[d$var=="inc10"] <- "3.FeatHHInc"
d$var[d$var=="inc40"] <- "2.FeatHHInc"
d$var[d$var=="inc70"] <- "1.FeatHHInc"

#group vars
variables <- c("0b.FeatDamage", "1.FeatDamage", "2.FeatDamage", "3.FeatDamage",
               "0b.FeatDead", "1.FeatDead",
               "0b.FeatHHInc", "1.FeatHHInc", "2.FeatHHInc", "3.FeatHHInc",
               "0b.FeatUnemp", "1.FeatUnemp", "2.FeatUnemp", "3.FeatUnemp",
               "1b.FeatPresVote", "2.FeatPresVote", "3.FeatPresVote", "4.FeatPresVote", "5.FeatPresVote")

d$gruppe <- NA

d$var <- rownames(d)

d$gruppe[d$var %in% Damage]    <- "Economic Damage"
d$gruppe[d$var %in% Fatalities]   <- "Number of Dead People"
d$gruppe[d$var %in% Income] <- "Household Income"
d$gruppe[d$var %in% Unemployment]     <- "Unemployment Rate"
d$gruppe[d$var %in% VoteShare]     <- "Presidential Vote (t-1)"

d <- d[order(d$order),]
dd <- data.frame(var= c("Economic Damage:",
                        "Fatalities:",
                        "Income:",
                        "Unemployment Rate:",
                        "Presidential Vote Share:"),
                 order=c(.5,4.5,6.5,10.5,14.5),
                 pe=0,se=0,upper=0,lower=0,gruppe=NA)

d <- rbind(d,dd)
d <-d[order(d$order),]

d$counter <- seq(1,nrow(d),1)
d$counter <- d$counter*-1 + nrow(d) + 1
d$var <- factor(d$var,levels=unique(d$var)[length(d$var):1])
d$gruppe <- factor(d$gruppe,levels=unique(d$gruppe))

d$pe[d$order==0.5 | d$order==4.5 | d$order==6.5 | d$order==10.5 | d$order==14.5] <- NA

xlabelsN <- c("70% Democrat, 30% Republican", "60% Democrat, 40% Republican", "30% Democrat, 70% Republican", "40% Democrat, 60% Republican", "50% Democrat, 50% Republican", "Presidential Vote in 2012:           ", "9%", "7%", "5%", "3%", "Unemployment Rate:                  ", "$10,000", "$40,000", "$70,000", "$100,000", "Average Household Income:       ", "5", "0", "Number of Fatalities:                   ", "$24 million", "$4 million", "$1 million", "$100,000", "Economic Damage:                    ")

### Simple plot 
p <- ggplot(d, aes(x=counter, y=pe)) + geom_point(size = 2)
p <- p + geom_linerange(aes(x=counter, ymin= lower, ymax=upper),  size=0.5)
p <- p + coord_flip(ylim = c(-0.7, 1.5), xlim = c(1,24)) + theme_bw()
p <- p + scale_x_continuous(name="", breaks=seq(1,24,1),labels=xlabelsN)
p <- p + scale_y_continuous(name="Change in Relief Aid (million $)")
p <- p + geom_hline(yintercept = 0,size=0.5,colour="black",linetype="dashed") 
fig8 = p +  theme(legend.position = "none", axis.text = element_text(size = 12)) 
fig8

ggsave("FigureA8_tobit.pdf", width=9, height=8)

###########################################################
# Figure A9: Observed vs. preferred (conjoint: Democratic president)
variables <- c("0b.FeatDamage", "1.FeatDamage", "2.FeatDamage", "3.FeatDamage",
               "0b.FeatDead", "1.FeatDead",
               "0b.FeatHHInc", "1.FeatHHInc", "2.FeatHHInc", "3.FeatHHInc",
               "0b.FeatUnemp", "1.FeatUnemp", "2.FeatUnemp", "3.FeatUnemp",
               "1b.FeatPresVote", "2.FeatPresVote", "3.FeatPresVote", "4.FeatPresVote", "5.FeatPresVote")

#Get historical data
model.empirical <- c("empirical_results.txt")
empirical <- read.table(model.empirical,header=TRUE)
new_row <- c(0,0)
empirical <- rbind(empirical, new_row)
empirical$ord <- 1:nrow(empirical)
empirical$ord[empirical$ord==34] <- 6.5
empirical <- empirical[order(empirical$ord),]
empirical <- within(empirical, rm(ord))

#Get conjoint data
model.conjoint <- c("olspres_dem_log.txt")
conjoint <- read.table(model.conjoint,header=TRUE)
new_row <- c(0,0)
conjoint <- rbind(conjoint, new_row)
conjoint$ord <- 1:nrow(conjoint)
conjoint$ord[conjoint$ord==20] <- 6.5
conjoint <- conjoint[order(conjoint$ord),]
conjoint <- within(conjoint, rm(ord))

#Drop unnecessary observations
empirical <- empirical[-c(34,33,32,31,30,29,28,27,26,25,24,23,22,21,20),]
conjoint <- conjoint[-c(nrow(conjoint)), ]

#calculate standard errors
empirical$r1 <- sqrt(empirical$r1)
conjoint$r1 <- sqrt(conjoint$r1)

#calculate confidence intervals
empirical$lower <- empirical$y1  - 1.96*empirical$r1
empirical$upper <- empirical$y1  + 1.96*empirical$r1

conjoint$lower <- conjoint$y1  - 1.96*conjoint$r1
conjoint$upper <- conjoint$y1  + 1.96*conjoint$r1


colnames(empirical) <- c("pe", "se", "lower", "upper")
colnames(conjoint) <- c("pe", "se", "lower", "upper")

#add order variable 
empirical$order <- c(seq(.8,3.8,1), seq(5.8,6.8,1), seq(8.8,11.8,1), seq(13.8,16.8,1), seq(18.8,22.8,1))
conjoint$order <- empirical$order + .4

#add variable to frames
empirical$variables <- variables
conjoint$variables <- variables

#add estimate type
empirical$Alloc <- "Observed allocation"
conjoint$Alloc <- "Preferred allocation"

mydata <- rbind(conjoint, empirical)
mydata$order <- mydata$order * -1 + 24

xlabelsN <- c("Opp. Stronghold / 70% Opp., 30% Core", "Opposition / 60% Opp., 40% Core", "Core Stronghold / 70% Core, 30% Opp.", "Core / 60% Core, 40% Opp.", "Swing / 50% D, 50% R", "Presidential Vote in 2012:           ", "7%-36% / 9%", "5%-7% / 7%", "4%-5% / 5%", "0%-4% / 3%", "Unemployment Rate:                  ", "$0k-$29K / $10K", "$29K-$34K / $40K", "$34K-$40K / $70K", "$40K-$104K / $100K", "Average Household Income:       ", "More than 0 / 5", "0 / 0", "Number of Fatalities:                   ", "10.9M-29.9B / 24M", "$2M-$11M / 4M", "$400K-2M / $1M", "$0-$400K / $100K", "Economic Damage:                    ")

mydata <- mutate(mydata, pe = pe*100, lower = lower*100, upper = upper*100)

p <- ggplot(mydata, aes(x=order, y=pe, colour=Alloc)) + 
  geom_point(aes(x = order, y = pe, colour = Alloc), show.legend = T, size = 2) +
  geom_segment(aes(x = order, xend = order, y = lower, yend = upper), show.legend = T) 
p <- p + coord_flip(ylim = c(-60, 90), xlim = c(1, 24)) + theme_bw()
p <- p + scale_x_continuous(name="", breaks=seq(1,24,1),labels=xlabelsN)
p <- p + scale_y_continuous(name="Change in Relief Aid (in %)",
                            breaks = c(-60,-30,0,30,60,90))
p <- p + geom_hline(yintercept = 0,size=.5,colour="black",linetype="dashed") 
fig9 <- p + theme(legend.position = c(.83, 0.965),
                  legend.background = element_rect(fill="transparent"),
                  legend.key = element_blank(), axis.text = element_text(size = 12)) + scale_colour_grey(name = "") 
fig9

ggsave("FigureA9_Observed_Preferred_Dem.pdf", width=9, height=8)

###########################################################
# Figure A10: z-transformed relief amount
model <- c("ztransformed.txt") 
modelname <- c("Change in relief aid")

d <- read.table(model, header=TRUE)
new_row <- c(0,0)
d <- rbind(d, new_row)
d$ord <- 1:nrow(d)
d$ord[d$ord==20] <- 6.5
d <- d[order(d$ord),]
d <- within(d, rm(ord))

# Drop the constant
d <- d[-c(length(d$y1)), ]

colnames(d) <- c("pe", "se")

d$se <- sqrt(d$se)

d$lower <- d$pe  - 1.96*d$se
d$upper <- d$pe  + 1.96*d$se

d$order <- 1:nrow(d)

#group vars
Damage <- c("0b.FeatDamage", "1.FeatDamage", "2.FeatDamage", "3.FeatDamage")
Fatalities <- c("0b.FeatDead", "1.FeatDead", "2.FeatDead", "3.FeatDead")
Income <- c("0b.FeatHHInc", "1.FeatHHInc", "2.FeatHHInc", "3.FeatHHInc")
Unemployment <- c("0b.FeatUnemp", "1.FeatUnemp", "2.FeatUnemp", "3.FeatUnemp")
VoteShare <- c("1b.FeatPresVote", "2.FeatPresVote", "3.FeatPresVote", "4.FeatPresVote", "5.FeatPresVote")


d$gruppe <- NA
d$var <- rownames(d)
d$var[d$var==20] <- "0b.FeatHHInc"
d$var[d$var=="inc10"] <- "3.FeatHHInc"
d$var[d$var=="inc40"] <- "2.FeatHHInc"
d$var[d$var=="inc70"] <- "1.FeatHHInc"

#group vars
variables <- c("0b.FeatDamage", "1.FeatDamage", "2.FeatDamage", "3.FeatDamage",
               "0b.FeatDead", "1.FeatDead",
               "0b.FeatHHInc", "1.FeatHHInc", "2.FeatHHInc", "3.FeatHHInc",
               "0b.FeatUnemp", "1.FeatUnemp", "2.FeatUnemp", "3.FeatUnemp",
               "1b.FeatPresVote", "2.FeatPresVote", "3.FeatPresVote", "4.FeatPresVote", "5.FeatPresVote")

d$gruppe <- NA

d$var <- rownames(d)

d$gruppe[d$var %in% Damage]    <- "Economic Damage"
d$gruppe[d$var %in% Fatalities]   <- "Number of Dead People"
d$gruppe[d$var %in% Income] <- "Household Income"
d$gruppe[d$var %in% Unemployment]     <- "Unemployment Rate"
d$gruppe[d$var %in% VoteShare]     <- "Presidential Vote (t-1)"

#DEPENDING ON THE MODEL SPECIFIED YUO HAVE TO ADJUST THE ORDER
d <- d[order(d$order),]
dd <- data.frame(var= c("Economic Damage:",
                        "Fatalities:",
                        "Income:",
                        "Unemployment Rate:",
                        "Presidential Vote Share:"),
                 order=c(.5,4.5,6.5,10.5,14.5),
                 pe=0,se=0,upper=0,lower=0,gruppe=NA)

d <- rbind(d,dd)
d <-d[order(d$order),]

d$counter <- seq(1,nrow(d),1)
d$counter <- d$counter*-1 + nrow(d) + 1
d$var <- factor(d$var,levels=unique(d$var)[length(d$var):1])
d$gruppe <- factor(d$gruppe,levels=unique(d$gruppe))

d$pe[d$order==0.5 | d$order==4.5 | d$order==6.5 | d$order==10.5 | d$order==14.5] <- NA

# Reverse order!!!
xlabelsN <- c("70% Democrat, 30% Republican", "60% Democrat, 40% Republican", "30% Democrat, 70% Republican", "40% Democrat, 60% Republican", "50% Democrat, 50% Republican", "Presidential Vote in 2012:           ", "9%", "7%", "5%", "3%", "Unemployment Rate:                  ", "$10,000", "$40,000", "$70,000", "$100,000", "Average Household Income:       ", "5", "0", "Number of Fatalities:                   ", "$24 million", "$4 million", "$1 million", "$100,000", "Economic Damage:                    ")


#d <- mutate(d, pe = pe*100, lower = lower*100, upper = upper*100)

### Simple plot 
p <- ggplot(d, aes(x=counter, y=pe)) + geom_point(size = 2)
p <- p + geom_linerange(aes(x=counter, ymin= lower, ymax=upper),  size=0.5)
p <- p + coord_flip(ylim = c(-0.25, 0.75), xlim = c(1,24)) + theme_bw()
p <- p + scale_x_continuous(name="", breaks=seq(1,24,1),labels=xlabelsN)
p <- p + scale_y_continuous(name="Change in z-score")
p <- p + geom_hline(yintercept = 0,size=0.5,colour="black",linetype="dashed") 
fig10 = p +  theme(legend.position = "none", axis.text = element_text(size = 12)) 
fig10

ggsave("FigureA10_ztransformed.pdf", width=9, height=8)


###########################################################
# Figure A11: Main model vs. only one scenario
variables <- c("0b.FeatDamage", "1.FeatDamage", "2.FeatDamage", "3.FeatDamage",
               "0b.FeatDead", "1.FeatDead",
               "0b.FeatHHInc", "1.FeatHHInc", "2.FeatHHInc", "3.FeatHHInc",
               "0b.FeatUnemp", "1.FeatUnemp", "2.FeatUnemp", "3.FeatUnemp",
               "1b.FeatPresVote", "2.FeatPresVote", "3.FeatPresVote", "4.FeatPresVote", "5.FeatPresVote")

model.rep <- c("olscon_main.txt")
rep <- read.table(model.rep,header=TRUE)
new_row <- c(0,0)
rep <- rbind(rep, new_row)
rep$ord <- 1:nrow(rep)
rep$ord[rep$ord==20] <- 6.5
rep <- rep[order(rep$ord),]
rep <- within(rep, rm(ord))

model.dem <- c("szenario.txt")
dem <- read.table(model.dem,header=TRUE)
new_row <- c(0,0)
dem <- rbind(dem, new_row)
dem$ord <- 1:nrow(dem)
dem$ord[dem$ord==20] <- 6.5
dem <- dem[order(dem$ord),]
dem <- within(dem, rm(ord))

# Drop the constants
rep <- rep[-c(nrow(rep)), ]
dem <- dem[-c(nrow(dem)), ]

# calculate standard errors
rep$r1 <- sqrt(rep$r1)
dem$r1 <- sqrt(dem$r1)

# calculate confidence intervals
rep$lower <- rep$y1  - 1.96*rep$r1
rep$upper <- rep$y1  + 1.96*rep$r1

dem$lower <- dem$y1  - 1.96*dem$r1
dem$upper <- dem$y1  + 1.96*dem$r1

colnames(rep) <- c("pe", "se", "lower", "upper")
colnames(dem) <- c("pe", "se", "lower", "upper")

# add order variable 
rep$order <- c(seq(.8,3.8,1), seq(5.8,6.8,1), seq(8.8,11.8,1), seq(13.8,16.8,1), seq(18.8,22.8,1))
dem$order <- rep$order + .4

# add variable to frames
rep$variables <- variables
dem$variables <- variables

# add model variable
rep$model <- "Full sample"
dem$model <- "Scenario 1 only"

mydata <- rbind(rep,dem)
mydata$order <- mydata$order * -1 + 24

xlabelsN <- c("70% Democrat, 30% Republican", "60% Democrat, 40% Republican", "30% Democrat, 70% Republican", "40% Democrat, 60% Republican", "50% Democrat, 50% Republican", "Presidential Vote in 2012:           ", "9%", "7%", "5%", "3%", "Unemployment Rate:                  ", "$10,000", "$40,000", "$70,000", "$100,000", "Average Household Income:       ", "5", "0", "Number of Fatalities:                   ", "$24 million", "$4 million", "$1 million", "$100,000", "Economic Damage:                    ")

#mydata <- mutate(mydata, pe = pe*100, lower = lower*100, upper = upper*100)
mydata$model <- as.factor(mydata$model)
mydata$model <- factor(mydata$model, levels = c(levels(mydata$model)[1],levels(mydata$model)[2]))

p <- ggplot(mydata, aes(x=order, y=pe, colour=model)) + 
  geom_point(aes(x = order, y = pe, colour = model), show.legend = T, size = 2) +
  geom_segment(aes(x = order, xend = order, y = lower, yend = upper), show.legend = T) 
p <- p + coord_flip(ylim = c(-0.5, 1.5), xlim = c(1, 24)) + theme_bw()
p <- p + scale_x_continuous(name="", breaks=seq(1,24,1),labels=xlabelsN)
p <- p + scale_y_continuous(name="Change in Relief Aid (million $)")
p <- p + geom_hline(yintercept = 0,size=.5,colour="black",linetype="dashed") 
fig11 <- p + theme(legend.position = c(.83, 0.965),
                  legend.background = element_rect(fill="transparent"),
                  legend.key = element_blank(), axis.text = element_text(size = 12)) + scale_colour_grey(name = "") 

fig11
ggsave("FigureA11_onescenario.pdf", width=9, height=8)



